<?php
/**
 * Created by PhpStorm.
 * User: gaoliang
 * Date: 2017/5/24
 * Time: 10:48
 */
require_once dirname(dirname(__FILE__)).'/common/function/common.php';

//通过PMS的生成合同页面的HTMl，取到内容过来生成pdf
$url = getHttpType() . '://'.$_SERVER['HTTP_HOST'];

$tmpDir = 'file';
if(!is_dir($tmpDir))  mkdir($tmpDir);
//目标文件
$pdfPath = $tmpDir."/".date('YmdHis').".pdf";

$cmd = "wkhtmltopdf {$url} $pdfPath"; //执行，生成pdf文件命令
//文件不存在才再次生成
if (!file_exists($pdfPath)) shell_exec($cmd);
if (!file_exists($pdfPath)) exit('生成PDF文件失败');

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename= test.pdf");
echo file_get_contents($pdfPath);
unlink($pdfPath);